//
//  QZVideoPlayAnimation.m
//  Bullet
//
//  Created by admin on 2019/9/1.
//  Copyright © 2019 . All rights reserved.
//

#import "QZVideoPlayAnimation.h"

@implementation QZVideoPlayAnimation{
    NSTimer * VideoLoadAnimationTimer;
    UIImageView * AnimationView1;
    UIImageView * AnimationView2;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        AnimationView1 = [[UIImageView alloc]initWithFrame:CGRectMake(KScreen_W/2, 0, 0, 1)];
        AnimationView1.image = [UIImage imageNamed:@"animation_left"];
//        AnimationView1.backgroundColor = [UIColor whiteColor];
        AnimationView1.clipsToBounds = YES;
        [self addSubview:AnimationView1];
//        AnimationLayer1 = [CAGradientLayer layer];
//        AnimationLayer1.startPoint = CGPointMake(0, 0);//（0，0）表示从左上角开始变化。默认值是(0.5,0.0)表示从x轴为中间，y为顶端的开始变化
//        AnimationLayer1.endPoint = CGPointMake(1, 1);//（1，1）表示到右下角变化结束。默认值是(0.5,1.0)  表示从x轴为中间，y为低端的结束变化
//        AnimationLayer1.colors = [NSArray arrayWithObjects:(id)[UIColor whiteColor].CGColor,(id)[UIColor blackColor].CGColor, nil];
//        AnimationLayer1.frame = CGRectMake(0, 0, 0, 1);
//        [AnimationView1.layer insertSublayer:AnimationLayer1 atIndex:0];


        AnimationView2 = [[UIImageView alloc]initWithFrame:CGRectMake(KScreen_W/2, 0, 0, 1)];
        AnimationView2.image = [UIImage imageNamed:@"animation_right"];
        AnimationView2.clipsToBounds = YES;
        [self addSubview:AnimationView2];
//        AnimationLayer2 = [CAGradientLayer layer];
//        AnimationLayer2.startPoint = CGPointMake(0, 0);//（0，0）表示从左上角开始变化。默认值是(0.5,0.0)表示从x轴为中间，y为顶端的开始变化
//        AnimationLayer2.endPoint = CGPointMake(1, 1);//（1，1）表示到右下角变化结束。默认值是(0.5,1.0)  表示从x轴为中间，y为低端的结束变化
//        AnimationLayer2.colors = [NSArray arrayWithObjects:(id)[UIColor blackColor].CGColor,(id)[UIColor whiteColor].CGColor, nil];
//        AnimationLayer2.frame = CGRectMake(0, 0, 0, 1);
//        [AnimationView2.layer insertSublayer:AnimationLayer2 atIndex:0];
    UIButton * textShowButtonTo1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        NSString * textShowButtonTitleTo1 = @"测试功能";
        [textShowButtonTo1 setTitle:textShowButtonTitleTo1 forState:UIControlStateNormal];
        NSInteger textShowArcTo1 = arc4random_uniform(22);
        NSLog(@"随机数：%ld", (long)textShowArcTo1);
    }
    return self;
}

-(void)startAnimation{
    if (VideoLoadAnimationTimer != nil) {
        return;
    }
    VideoLoadAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(startTaP) userInfo:nil repeats:YES];
    [VideoLoadAnimationTimer fire];
}
-(void)startTaP{
    self->AnimationView1.frame = CGRectMake(KScreen_W/2, 0, 0, 1) ;
//    AnimationLayer1.frame = CGRectMake(0, 0, 0, 1);
    
    self->AnimationView2.frame = CGRectMake(KScreen_W/2, 0, 0, 1) ;
//    AnimationLayer2.frame = CGRectMake(0, 0, 0, 1);
    [UIView animateWithDuration:1 animations:^{
        self->AnimationView1.frame = CGRectMake(20, 0, KScreen_W/2-20, 1) ;
//        self->AnimationLayer1.frame = CGRectMake(0, 0, KScreen_W/2-20, 1);

        self->AnimationView2.frame = CGRectMake(KScreen_W/2, 0, KScreen_W/2-20, 1) ;
//        self->AnimationLayer2.frame = CGRectMake(0, 0, KScreen_W/2-20, 1);

    }];
}
-(void)endAnimation{
    [VideoLoadAnimationTimer invalidate];
    VideoLoadAnimationTimer = NULL;
}
@end
